
#include "main.h" 

/*
  ---------------------> 4 Bytes <---------------------

            ===== Time =====	 ======= Date ======

          	 ss.  mm.   hh.       dd.  mm.   yy.
    Bits:    0-4  5-10 11-15    16-20 21-24 25-31				
*/

//        8  11 14 17 20 23
//        |  |  |  |  |  |
//+CCLK: "06/06/14,18:47:47+12"

unsigned long TimePackage ( unsigned char* Time )
{
	unsigned long Result = 0, temp;
	
	/* Year */
	temp = StrToLong(Time+8);
	Result |= temp << 25; 

	/* Month */
	temp = StrToLong(Time+11);
	Result |= temp << 21;

	/* Day */
	temp = StrToLong(Time+14);
	Result |= temp << 16; 

	/* Hour */
	temp = StrToLong(Time+17);
	Result |= temp << 11; 
	
	/* Minutes */
	temp = StrToLong(Time+20);
	Result |= temp << 5; 

	/* Sec/2 */
	temp = StrToLong(Time+23);
	Result |= temp >> 1; 
	
	return Result;
}

/*
  ---------------------> 4 Bytes <---------------------
            ===== Time =====	 ======= Date ======

          	 ss.  mm.   hh.       dd.  mm.   yy.
    Bits:    0-4  5-10 11-15    16-20 21-24 25-31				
*/

unsigned char* TimeUnPackage ( unsigned char* Time,  unsigned long PackageTime )
{
	/* 14/06/06 18:47:47 */ 
	unsigned char temp, str[4];
	
	/* Day */
	temp = (PackageTime >> 16) & 0x1F;
	ByteToStr_10(str, temp);
	StrCat(str, "/");
	StrCpy(Time, str);	// "14/"

	/* Month */
	temp = (PackageTime >> 21) & 0x0F;
	ByteToStr_10(str, temp);
	StrCat(str, "/");
	StrCat(Time, str);	// "14/06/"
	
	/* Year */
	temp = (PackageTime >> 25) & 0x7F;
	ByteToStr_10(str, temp);
	StrCat(str, " ");
	StrCat(Time, str);	// "14/06/06 "

	/* Hours */
	temp = (PackageTime >> 11) & 0x1F;
	ByteToStr_10(str, temp);
	StrCat(str, ":");
	StrCat(Time, str);	// "14/06/06 18:"
	
	/* Minutes */
	temp = (PackageTime >> 5) & 0x3F;
	ByteToStr_10(str, temp);
/* 	StrCat(str, ":"); */
	StrCat(Time, str);	// "14/06/06 18:47"


	return Time;
} 
